/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.adama.constraint;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.regex.Pattern;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author avisto
 */
@Target(value = {ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
@Retention(value = RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = NumSiretConstraint.NumSiretValidator.class)
public @interface NumSiretConstraint {

    static final Logger logger = LoggerFactory.getLogger(NumSiretConstraint.class);

    String message() default "{fr.adama.constraint.numSiret.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    public class NumSiretValidator implements ConstraintValidator<NumSiretConstraint, String> {

        Pattern p = Pattern.compile("^[0-9]{3} ?[0-9]{3} ?[0-9]{3} ?[0-9]{5}");

        @Override
        public void initialize(final NumSiretConstraint hasId) {
        }

        @Override
        public boolean isValid(final String numSecu, final ConstraintValidatorContext constraintValidatorContext) {

//            return p.matcher(numSecu).find();
            return true;
        }

    }
}
